package com.ivr.cm.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

import com.ivr.cm.dao.IConfigRouterDao;
import com.ivr.cm.vo.ConfigRouterVo;

public class ConfigRouterDaoImpl extends JdbcDaoSupport implements IConfigRouterDao {
	private static Logger logger = Logger.getLogger(ConfigRouterDaoImpl.class);
	/**获得所有的路由信息*/
	@SuppressWarnings("unchecked")
	@Override
	public List<ConfigRouterVo> getConfigRouterVoList() {
		String sql = "select id, name, sp_number, is_self_consum, detail, sync_url, lower_id, start_second, end_second, status, reserve from tb_ivr_config_router where status = 1";
		logger.info(String.format("获得所有的路由信息[%s]", sql));
		
		List<ConfigRouterVo> configRouterVoList = this.getJdbcTemplate().query(sql,rowMapper);
		if(configRouterVoList != null && configRouterVoList.size() > 0){
			return configRouterVoList;
		}
		return null;
	}
	
	private ParameterizedRowMapper<ConfigRouterVo> rowMapper = new ParameterizedRowMapper<ConfigRouterVo>() {
		@Override
		public ConfigRouterVo mapRow(ResultSet rs, int rowNum) throws SQLException {
			ConfigRouterVo configRouterVo = new ConfigRouterVo();
			configRouterVo.setId(rs.getInt("id"));
			configRouterVo.setName(rs.getString("name"));
			configRouterVo.setSp_number(rs.getString("sp_number"));
			configRouterVo.setIs_self_consum(rs.getInt("is_self_consum"));
			configRouterVo.setDetail(rs.getString("detail"));
			configRouterVo.setSync_url(rs.getString("sync_url"));
			configRouterVo.setLower_id(rs.getInt("lower_id"));
			configRouterVo.setStatus(rs.getInt("status"));
			configRouterVo.setReserve(rs.getString("reserve"));
			configRouterVo.setStart_second(rs.getInt("start_second"));
			configRouterVo.setEnd_second(rs.getInt("end_second"));
			return configRouterVo;
		}
	};

}
